package agriculture.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ配置 - 定义交换机、队列、绑定
 */
@Configuration
public class RabbitMQConfig {
    public static final String EXCHANGE_NAME = "order.exchange";//交换机
    public static final String QUEUE_NAME = "order.paid.queue";//队列
    public static final String ROUTING_KEY = "order.paid";

    @Bean
    public Exchange orderExchange() {
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    @Bean
    public Queue orderPaidQueue() {
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    @Bean
    public Binding orderPaidBinding() {
        return BindingBuilder
                .bind(orderPaidQueue())
                .to(orderExchange())
                .with(ROUTING_KEY)
                .noargs();
    }
}
